home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 118 / cd-rom 118.iso / aplic / open / openofficeorg1.cab / FilesModul.xba < prev    next >
Encoding:
Extensible Markup Language  |  2005-01-31  |  28.5 KB  |  817 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FilesModul" script:language="StarBasic">Option Explicit
  4.  
  5. Public AbsTemplateFound as Integer
  6. Public AbsDocuFound as Integer
  7. Public oLogDocument as Object
  8. Public oLogTable as Object
  9. Public bLogExists as Boolean
  10. Public sComment as String
  11. Public MaxCollectIndex as Integer
  12. Public bInsertRow as Boolean
  13. Public sLogUrl as String
  14. Public sCurPassWord as String
  15. Public FileCount as Integer
  16. Public XMLTemplateCount as Integer
  17. Public PathCollection(7,3) as String
  18. Public bIsFirstLogTable as Boolean
  19. Public bFilterTracerIsinsideTable as Boolean
  20.  
  21.  
  22. Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
  23. Dim FilterIndex as Integer
  24. Dim bRecursive as Boolean
  25. Dim SearchDir as String
  26. Dim i as Integer
  27. Dim n as Integer
  28. Dim a as Integer
  29. Dim s as Integer
  30. Dim t as Integer
  31. Dim sFileContent() as String
  32. Dim NewList(0,1) as String
  33. Dim Index as Integer
  34. Dim CurFileName as String
  35. Dim CurExtension as String
  36. Dim CurFileContent as String
  37. Dim XMLTemplateContentList() as String
  38. Dim bIsTemplatePath as Boolean
  39. Dim MaxIndex as Integer
  40. Dim NewContentList() as String
  41. Dim XMLTemplateContentString as String
  42. Dim ApplIndex as Integer
  43. Dim bAssignFileName as Boolean
  44.     oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  45.     bInterruptSearch = False
  46.     For i = 0 To MaxCollectIndex
  47.         SearchDir = PathCollection(i,0)
  48.         bRecursive = PathCollection(i,1)
  49.         sFileContent() = ArrayoutofString(PathCollection(i,2), "|")
  50.         NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), "")
  51.         If InterruptProcess Then
  52.             ReadCollectionPaths() = False
  53.             Exit Function
  54.         End If
  55.         If Ubound(NewList()) > -1 Then
  56.             bIsTemplatePath = FieldInList("vor", sFileContent)
  57.             If bIsTemplatePath Then
  58.                 XMLTemplateContentString = PathCollection(i,3)
  59.                 XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, "|")
  60.                 If Ubound(XMLTemplateContentList()) > -1 Then
  61.                     MaxIndex = Ubound(NewList())
  62.                     ReDim Preserve NewList(MaxIndex, 1) as String
  63.                     ReDim Preserve NewContentList(MaxIndex) as String
  64.                     a = -1
  65.                     For n = 0 To MaxIndex
  66.                         bAssignFileName = True
  67.                         If InterruptProcess() Then
  68.                             ReadCollectionPaths() = False
  69.                             Exit Function
  70.                         End If
  71.                         CurFileContent = ""
  72.                         CurFileName = NewList(n,0)                                                    
  73.                         If (FieldInList(NewList(n,1), XMLTemplateList())) Then
  74.                             CurFileContent = GetRealFileContent(oDocInfo, CurFileName)
  75.                             t = SearchArrayforPartString(CurFileContent, XMLTemplateContentList())
  76.                              bAssignFileName = (t > -1)
  77.                              If bAssignFileName Then
  78.                                  CurFileContent = XMLTemplateContentList(t)
  79.                              End If
  80.                             NewList(n,1) = CurFileContent
  81.                         End If
  82.                         CurExtension = NewList(n,1)
  83.                         If bAssignFileName Then
  84.                             If a < n Then
  85.                                 a = a + 1
  86.                                 NewList(a,0) = CurFileName
  87.                                 NewList(a,1) = CurExtension
  88.                                 If CurFileContent = "" Then
  89.                                     CurFileContent = CurExtension
  90.                                 End If
  91.                                 ApplIndex = GetApplicationIndex(CurFileContent, sFiltername())
  92.                                 NewContentList(a) = ApplIndex
  93.                             End If
  94.                         End If
  95.                     Next n
  96.                     If a < MaxIndex And a > -1 Then
  97.                         ReDim Preserve NewList(a, 1) as String
  98.                     End If
  99.                     If a > -1 Then
  100.                         AddListtoFilesList(FilesList(), NewList(), NewContentList())
  101.                     End If
  102.                 End If
  103.             Else
  104.                 MaxIndex = Ubound(NewList())
  105.                 ReDim Preserve NewContentList(MaxIndex) as String
  106.                 For s = 0 To MaxIndex
  107.                     CurExtension = NewList(s,1)
  108.                     NewContentList(s) = GetApplicationIndex(CurExtension, sFiltername())
  109.                 Next s
  110.                 AddListtoFilesList(FilesList(), NewList(), NewContentList())
  111.             End If
  112.         End If
  113.     Next i
  114.     ReadCollectionPaths() = Ubound(FilesList()) > -1
  115. End Function
  116.  
  117.  
  118. Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
  119. Dim Index as Integer
  120. Dim i as Integer
  121.     Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  122.     If Index >= MaxApplCount Then
  123.         Index = Index - MaxApplCount
  124.     End If
  125.     For i = 0 To MaxApplCount - 1
  126.         If Applications(i, SBAPPLKEY) = Index Then
  127.             GetApplicationIndex() = i
  128.             Exit Function
  129.         End If
  130.     Next i
  131.     GetApplicationIndex() = - 1
  132. End Function
  133.  
  134.  
  135. Function InterruptProcess() as Boolean
  136.     If bCancelTask Or RetValue = 0 Then
  137.         bConversionIsRunning = False
  138.         InterruptProcess() = True
  139.         Exit Function
  140.     End if        
  141.     InterruptProcess() = False
  142. End Function
  143.  
  144.  
  145. Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  146.     MaxCollectIndex = MaxCollectIndex + 1
  147.     PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
  148.     PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
  149.     AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
  150. End Sub
  151.  
  152.  
  153. Function SetExtension(LocExtension) as String
  154.     if (Instr(LocExtension, "vnd.sun.xml.impress")) > 0 then
  155.         SetExtension() = "vor|sti"
  156.     elseif (Instr(LocExtension, "vnd.sun.xml.writer")) > 0 then
  157.         SetExtension() = "vor|stw"    
  158.     elseif (Instr(LocExtension, "vnd.sun.xml.calc")) > 0 then
  159.         SetExtension() = "vor|stc"
  160.     endif
  161. End Function
  162.  
  163. Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
  164. Dim iKey as Integer
  165. Dim CurListString as String
  166. Dim LocExtension as String
  167. Dim LocContentString as String
  168. Dim LocXMLTemplateContent as String
  169.     iKey = Applications(ApplIndex, SBAPPLKEY)
  170.     CurListString = PathCollection(CollectIndex, 2)
  171.     LocExtension = sFilterName(iKey +DistIndex, 0)
  172.     If Len(LocExtension) > SBMAXEXTENSIONLENGTH Then             ' 7 == Length of two extensions like 'sda|sdd
  173.         LocExtension = SetExtension(LocExtension)
  174.         LocContentString = sFilterName(iKey +DistIndex, 0)
  175.         LocContentString = ReplaceString(LocContentString, "|", ";")
  176.         LocXMLTemplateContent = PathCollection(CollectIndex, 3)
  177.         If LocXMLTemplateContent = "" Then
  178.             LocXMLTemplateContent = LocContentString
  179.         Else
  180.             LocXMLTemplateContent = LocXMLTemplateContent & "|" & LocContentString
  181.         End If
  182.         PathCollection(CollectIndex, 3) = LocXMLTemplateContent
  183.     End If
  184.     If CurListString = "" Then
  185.         PathCollection(CollectIndex, 2) = LocExtension
  186.     Else
  187.         If Instr(CurListString, LocExtension) = 0 Then
  188.             PathCollection(CollectIndex, 2) = CurListString & "|" & LocExtension
  189.         End If
  190.     End If
  191. End Sub
  192.  
  193.  
  194. Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  195. Dim CollectIndex as Integer
  196. Dim bCheckDocuType as Boolean
  197.     bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
  198.     If bCheckDocuType Then
  199.         CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
  200.         If (CollectIndex >-1) Then
  201.             If Applications(ApplIndex, RecursiveIndex) <> PathCollection(CollectIndex, 1) Then
  202.                 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  203.             Else
  204.                 AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
  205.             End If
  206.         Else
  207.             AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  208.         End If
  209.     End If
  210. End Sub
  211.  
  212.  
  213. Sub CollectPaths(sFiltername() as String)
  214. Dim i as Integer
  215. Dim    XMLTemplateContentString as String
  216.     MaxCollectIndex = -1
  217.     For i = 0 To ApplCount-1
  218.         CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
  219.     Next i
  220.     XMLTemplateCount = 0
  221.     XMLTemplateContentString = ""
  222.     For i = 0 To ApplCount-1
  223.         If WizardMode = SBXMLMODE Then
  224.             XMLTemplateCount = XMLTemplateCount + 1
  225.         End If
  226.         CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
  227.     Next i
  228. End Sub
  229.  
  230.  
  231. Sub ConvertAllDocuments(sFilterName() as String)
  232. Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
  233. Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
  234. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  235. Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
  236. Dim    oInteractionHandler as Object
  237. Dim InteractionTypes(0) as Long
  238. Dim FilesList(0,2) as String
  239. Dim sViewPath as String
  240. Dim i as Integer
  241. Dim FilterIndex as Integer
  242. Dim sSourceUrl as String
  243. Dim CurFilename as String
  244. Dim oDocument as Object
  245. Dim sExtension as String
  246. Dim OldExtension as String
  247. Dim CurFound as Integer
  248. Dim TotFound as Integer
  249. Dim TargetStemDir as String
  250. Dim SourceStemDir as String
  251. Dim TargetDir as String
  252. Dim sTargetUrl as String
  253. Dim CurFilterName as String
  254. Dim ApplIndex as Integer
  255. Dim Index as Integer
  256. Dim bIsDocument as Boolean
  257. Dim bDoSave as Boolean
  258. Dim sCurFileExists as String
  259. Dim MaxFileIndex as Integer
  260. Dim bContainsBasicMacro as Boolean
  261. Dim bIsPassWordProtected as Boolean
  262. Dim iOverwrite as Integer
  263. Dim sMimeTypeorExtension as String
  264. Dim sPrevMimeTypeorExtension as String
  265.     bConversionisrunning = True
  266.     InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
  267.     oInteractionHandler = createUnoService("com.sun.star.task.InteractionHandler")
  268.     oInteractionHandler.initialize(InteractionTypes())
  269.     iGeneralOverwrite = SBOVERWRITEUNDEFINED
  270.     bConversionIsRunning = True
  271.     bLogExists = false
  272.     AbsTemplateFound = 0
  273.     AbsDocuFound = 0
  274.     CollectPaths(sFiltername())
  275.     If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
  276.         TotFound = 0
  277.         SetProgressDisplay(0)
  278.         bConversionisrunning = false
  279.         FinalizeDialogButtons()    
  280.         Exit Sub
  281.     End If
  282.     TotFound = Ubound(FilesList()) + 1             
  283.     If FilesList(0,0) = "" Then                    ' Querying the number of fields in a multidimensionl Array is unsecure
  284.         TotFound = 0                            ' because it will return the value 0 (and not -1) even when the Array is empty
  285.         SetProgressDisplay(0)
  286.     End If
  287.     BubbleSortList(FilesList(), true)
  288.     If TotFound > 0 Then
  289.         CreateLogDocument(OpenProperties())
  290.         InitializeProgressPage(ImportDialog)
  291.         OpenProperties(0).Name = "Hidden"
  292.         OpenProperties(0).Value = True
  293.         OpenProperties(1).Name = "AsTemplate"
  294.         OpenProperties(1).Value = False
  295.         OpenProperties(2).Name = "MacroExecutionMode"
  296.         OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE    
  297.         OpenProperties(3).Name = "UpdateDocMode"
  298.         OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
  299.         OpenProperties(4).Name = "InteractionHandler"
  300.         OpenProperties(4).Value = oInteractionHandler
  301.         MaxFileIndex = Ubound(FilesList(),1)
  302.         FileCount = 0
  303.         For i = 0 To MaxFileIndex
  304.             sComment = ""
  305.             If InterruptProcess() Then
  306.                 Exit For
  307.             End If
  308.             bDoSave = True
  309.             sSourceUrl = FilesList(i,0)
  310.             sPrevMimeTypeorExtension = sMimeTypeorExtension
  311.             sMimeTypeorExtension = FilesList(i,1)
  312.             CurFiltername =    GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
  313.             ApplIndex = FilesList(i,2)
  314.             If sMimeTypeorExtension <> sPrevMimeTypeorExtension Then
  315.                 CreateLogTable(ApplIndex, sMimeTypeOrExtension, sFiltername()
  316.             End If
  317.             If ApplIndex > Ubound(Applications) or (ApplIndex < 0) Then
  318.                 Msgbox "Applicationindex out of bounds:" & sSourcUrl
  319.             End If
  320.             sViewPath = ConvertFromUrl(sSourceUrl)     ' CutPathView(sSourceUrl, 70)
  321.             ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & "  (" & sViewPath & ")"
  322.             Select Case lcase(sExtension)
  323.                 Case "odt", "ods", "odp", "odd", "odm", "odf" 
  324.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
  325.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
  326.                 Case Else                                 ' Templates and Helper-Applications remain
  327.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
  328.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
  329.             End Select
  330.             sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
  331.             CurFilename = GetFileNameWithoutExtension(sTargetUrl, "/")
  332.             OldExtension = GetFileNameExtension(sTargetUrl)
  333.             sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
  334.             sTargetUrl = sTargetUrl & sExtension
  335.             TargetDir = RTrimStr(sTargetUrl, CurFilename & "." & sExtension)
  336.             If (oUcb.Exists(sTargetUrl)) Then
  337.                 If (iGeneralOverwrite <> SBOVERWRITEALWAYS) Then
  338.                     If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
  339.                         ShowOverwriteAllDialog(sTargetUrl, sTitle)
  340.                         bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
  341.                     Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
  342.                         bDoSave = False                    
  343.                     ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
  344.                         ' Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog. 
  345.                         ' In this case my own UI becomes obsolete
  346.                         sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), "<1>")
  347.                         sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  348.                         iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  349.                         Select Case iOverWrite
  350.                             Case 1    ' OK
  351.                                 ' In the FileProperty-Bean this is already default
  352.                                 bDoSave = True
  353.                             Case 2     ' Abort
  354.                                 CancelTask(False)
  355.                                 bDoSave = False
  356.                             Case 7     ' No
  357.                                 bDoSave = False
  358.                         End Select
  359.                     End If
  360.                 End If
  361.             End If
  362.             If bDoSave Then
  363.                 If Not oUcb.Exists(TargetDir) Then
  364.                     bDoSave = CreateFolder(TargetDir)
  365.                 End If
  366.                 If bDoSave Then
  367.                     oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, "_default", 0, OpenProperties())
  368.                     If Not IsNull(oDocument) Then
  369.                         InsertSourceUrlToLogDocument(sSourceUrl, "")
  370.                         bIsPassWordProtected = CheckPassWordProtection(oDocument)
  371.                         CheckIfMacroExists(oDocument.BasicLibraries, sComment)
  372.                         On Local Error Goto NOSAVING
  373.                         If bIsPassWordProtected Then
  374.                             PWFileProperties(0).Name = "FilterName"
  375.                             PWFileProperties(0).Value = CurFilterName
  376.                             PWFileProperties(1).Name = "Overwrite"
  377.                             PWFileProperties(1).Value = True
  378.                             PWFileProperties(2).Name = "Password"
  379.                             PWFileProperties(2).Value = sCurPassWord
  380.                             oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
  381.                         Else
  382.                             FileProperties(0).Name = "FilterName"
  383.                             FileProperties(0).Value = CurFilterName
  384.                             FileProperties(1).Name = "Overwrite"
  385.                             FileProperties(1).Value = True
  386.                             oDocument.StoreAsUrl(sTargetUrl,FileProperties())
  387.                         End If
  388.                         ' Todo: Make sure that an errorbox pops up when saving fails
  389.                         NOSAVING:
  390.                         If Err <> 0 Then
  391.                             sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), "<1>")
  392.                             sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
  393.                             Resume LETSGO
  394.                             LETSGO:
  395.                         Else
  396.                             FileCount = FileCount + 1
  397.                         End If
  398.                         oDocument.Dispose()
  399.                         InsertTargetUrlToLogDocument(sTargetUrl, sComment, ApplIndex)
  400.                     Else
  401.                         sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), "<1>")
  402.                         sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
  403.                         InsertSourceUrlToLogDocument(sSourceUrl, sComment)
  404.                     End If
  405.                 End If
  406.             End If
  407.         Next i
  408.     End If
  409.     AddLogStatistics()
  410.     FinalizeDialogButtons()
  411.     bConversionIsRunning = False
  412.     Exit Sub
  413. RTError:
  414.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  415. End Sub
  416.  
  417.  
  418.  
  419. Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
  420. Dim sLocExtension as String
  421. Dim FirstStart as Integer
  422. Dim FirstEnd as Integer
  423. Dim i as Integer
  424. Dim s as Integer
  425.     If FirstList(0,0) = "" Then
  426.         FirstStart = Ubound(FirstList(),1)
  427.     Else
  428.         FirstStart = Ubound(FirstList(),1) + 1
  429.     End If
  430.     FirstEnd = FirstStart + Ubound(SecList(),1)
  431.     ReDim Preserve FirstList(FirstEnd,2)
  432.     s = 0
  433.     For i = FirstStart To FirstEnd
  434.         FirstList(i,0) = SecList(s,0)
  435.         FirstList(i,1) = SecList(s,1)
  436.         sLocExtension = lcase(FirstList(i,1))
  437.         Select Case sLocExtension
  438.             Case "sdw", "sdc", "sda", "sdd", "smf", "sgl", "doc", "xls", "ppt", "sxi" , "sxw" , "sxd" , "sxg" , "sxm" , "sxc" 
  439.                 AbsDocuFound = AbsDocuFound + 1
  440.             Case else
  441.                 AbsTemplateFound = AbsTemplateFound + 1
  442.         End Select
  443.         FirstList(i,2) = CStr(NewContentList(s))
  444.         s = s + 1
  445.     Next i
  446.     SetProgressDisplay(Ubound(FirstList()) + 1)
  447. End Sub
  448.  
  449.  
  450.  
  451. Function GetTargetTemplatePath(Index as Integer)
  452.     Select Case WizardMode
  453.         Case SBMICROSOFTMODE
  454.             GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
  455.         Case SBXMLMODE
  456.             If Index = 3 Then
  457.                 ' Helper Application
  458.                 GetTargetTemplatePath = SOWorkPath
  459.             Else
  460.                 GetTargetTemplatePath = SOTemplatePath
  461.             End If
  462.     End Select
  463. End Function
  464.  
  465.  
  466. ' Retrieves the second value for a next to 'SearchString' in
  467. ' a two-dimensional string-Array
  468. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  469. Dim i as Integer
  470. Dim MaxIndex as Integer
  471. Dim sLocFilterlist() as String
  472.     For i = 0 To Ubound(sFiltername(),1)
  473.         If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
  474.             sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
  475.             If MaxIndex = 0 Then
  476.                 sExtension = sFiltername(i,2)
  477.                 GetFilterName = sFilterName(i,1)
  478.             Else
  479.                 Dim b as Integer
  480.                 Dim sLocExtensionList() as String
  481.                 b =    SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  482.                 sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
  483.                 GetFilterName = sLocFilterList(b)
  484.                 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
  485.                 sExtension = sLocExtensionList(b)
  486.             End If
  487.             Exit For
  488.         End If
  489.     Next
  490.     FilterIndex = i
  491. End Function
  492.  
  493.  
  494. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  495. Dim i as Integer
  496. Dim a as Integer
  497. Dim StringList() as String
  498.     For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  499.         StringList() = ArrayoutofString(LocList(i), "|")
  500.         For a = 0 To Ubound(StringList())
  501.             If (Instr(1, SearchString, StringList(a)) <> 0) Then
  502.                 SearchArrayForPartString() = i
  503.                 Exit Function
  504.             End If
  505.         Next a
  506.     Next i
  507.     SearchArrayForPartString() = -1    
  508. End Function
  509.  
  510.  
  511. Sub CreateLogTable(ApplIndex as Integer, CurFileContent as String, sFilterName() as String)
  512. Dim oLogCursor as Object
  513. Dim oLogRows as Object
  514. Dim FilterIndex as Integer
  515. Dim sDocumentType as String
  516. Dim oTextCursor
  517. Dim oCell
  518.     bFilterTracerIsinsideTable = False
  519.     FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  520.     sDocumentType = sFiltername(FilterIndex,3)
  521.     oLogCursor = oLogDocument.Text.createTextCursor()
  522.     oLogCursor.GotoEnd(False)
  523.     If Not bIsFirstLogTable Then
  524.         oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  525.     Else
  526.         bisFirstLogTable = False
  527.     End If
  528.     oLogCursor.HyperLinkURL = ""
  529.     oLogCursor.HyperLinkName = ""
  530.     oLogCursor.HyperLinkTarget = ""
  531.     oLogCursor.ParaStyleName = "Heading 1"
  532.     oLogCursor.setString(sDocumentType)
  533.     If WizardMode = SBMICROSOFTMODE Then
  534.         If bFilterTracingAvailable Then
  535.             If bMSApplFilterTracingAvailable(ApplIndex) Then
  536.                 Dim CurFilterTracingPath as String
  537.                 CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  538.                 bFilterTracerIsinsideTable = (bTakeOverTargetName(ApplIndex) Or bTakeOverPathName(ApplIndex))
  539.                 If Not bFilterTracerIsinsideTable Then
  540.                     oLogCursor.CollapseToEnd()
  541.                     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  542.                     InsertCommandButtonatViewCursor(oLogDocument, oLogCursor, CurFilterTracingPath)
  543.                 End If
  544.             End If
  545.         End If
  546.     End If
  547.     oLogCursor.CollapsetoEnd()
  548.     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  549.     oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  550.     oLogTable.RepeatHeadline = true
  551.     If bFilterTracerIsinsideTable Then
  552.         oLogTable.initialize(2,3)
  553.     End If
  554.     oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  555.     oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  556.     oTextCursor.SetString(sSourceDocuments)    
  557.     oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  558.     oTextCursor.SetString(sTargetDocuments)
  559.     If bFilterTracerIsinsideTable Then
  560.         oTextCursor = oLogTable.GetCellbyPosition(2,0).createTextCursor()
  561.         oTextCursor.SetString("FilterTracer")
  562.     End If
  563.     bInsertRow = False
  564. End Sub
  565.  
  566.  
  567. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  568. Dim aSize As New com.sun.star.awt.Size
  569.     aSize.Width = iWidth
  570.     aSize.Height = iHeight
  571.     GetSize() = aSize
  572. End Function
  573.  
  574.  
  575. Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
  576. Dim oDocument
  577. Dim oController
  578. Dim oCommandButton
  579. Dim oShape
  580. Dim oDrawPage
  581. Dim oCommandControl
  582. Dim oEvent
  583. Dim oCell
  584.     oCommandButton = oLocDocument.createInstance("com.sun.star.form.component.CommandButton")
  585.     oShape = oLocDocument.CreateInstance ("com.sun.star.drawing.ControlShape")    
  586.     If IsMissing(aSize) Then
  587.         oShape.Size = GetSize(4000, 600)
  588.     End If
  589.     oCommandButton.Label = FileNameoutofPath(Targeturl)
  590.     oCommandButton.TargetFrame = "_default"
  591.     oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
  592.     oCommandbutton.DispatchUrlInternal = True
  593.     oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
  594.     oShape.Control = oCommandbutton
  595.     oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
  596. End Sub
  597.  
  598.  
  599.  
  600. Sub CreateLogDocument(HiddenProperties())
  601. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  602. Dim NoArgs()
  603. Dim i as Integer
  604. Dim bLogIsThere as Boolean
  605.     If ImportDialog.chkLogfile.State = 1 Then
  606.         i = 2
  607.         OpenProperties(0).Name = "Hidden"
  608.         OpenProperties(0).Value = True
  609.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_default", 4, OpenProperties())
  610.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  611.         Do
  612.             bLogIsThere = oUcb.Exists(sLogUrl)
  613.             If bLogIsThere Then
  614.                 If i = 2 Then
  615.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  616.                 Else
  617.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  618.                 End If
  619.                 i = i + 1
  620.             End If
  621.         Loop Until Not bLogIsThere
  622.         bLogExists = True
  623.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  624.     End If
  625. End Sub
  626.  
  627.  
  628. Function GetFilterTracingLogPath(sTargetUrl as String, ApplIndex) as String                
  629. Dim TargetFileName as String
  630. Dim sTargetFolder as String
  631. Dim CurFilterTracingPath as String
  632. Dim CurFilterTracingname as String
  633. Dim CurFilterFolder as String
  634.         CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  635.         If bTakeOverTargetName(ApplIndex) Then            
  636.             TargetFilename = GetFileNameWithoutextension(sTargetUrl, "/")
  637.             CurFilterFolder = DirectoryNameoutofPath(FilterTracingLogPath(ApplIndex), "/")
  638.             CurFilterTracingpath = CurFilterFolder & "/" & TargetFilename & ".log"
  639.         End If
  640.         If bTakeOverPathName(ApplIndex) Then  'Replace the Folder in the FilterTracerpath by the Folder of the targetUrl
  641.             sTargetFolder = DirectoryNameoutofPath(sTargetUrl,"/")
  642.             CurFilterTracingPath = sTargetFolder & "/" & FileNameoutofPath(CurFilterTracingPath, "/")
  643.         End If
  644.         GetFilterTracingLogPath() = CurFilterTracingPath
  645. End Function
  646.  
  647.  
  648. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String, ApplIndex as Integer)
  649. Dim oCell
  650. Dim oTextCursor
  651. Dim CurFilterTracingpath as String
  652.     If (bLogExists) And (sTargetUrl <> "") Then
  653.         If sTargetUrl <> "" Then
  654.             oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  655.             InsertCommentToLogCell(sComment, oCell)
  656.             InsertHyperLinkToLogCell(sTargetUrl, oCell)
  657.             If bFilterTracerIsinsideTable Then
  658.                 oCell = oLogTable.getCellByPosition(2, oLogTable.Rows.Count-1)
  659.                 oTextCursor = oCell.Text.CreateTextCursor()
  660.                 CurFilterTracingpath = GetFilterTracingLogPath(sTargetUrl, ApplIndex)
  661.                 InsertCommandButtonatViewCursor(oLogDocument, oTextCursor, CurFilterTracingPath)
  662.             End If
  663.             oLogDocument.Store()
  664.         End If
  665.     End If
  666. End Sub
  667.  
  668.  
  669. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)        '
  670. Dim oCell as Object
  671.     If bLogExists Then
  672.         If bInsertRow Then
  673.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  674.         Else
  675.             bInsertRow = True
  676.         End If
  677.         oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  678.         InsertCommentToLogCell(sComment, oCell)
  679.         InsertHyperLinkToLogCell(SourceUrl, oCell)
  680.         oLogDocument.Store()
  681.     End If
  682. End Sub
  683.  
  684.  
  685. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  686. Dim oLogCursor as Object
  687. Dim LocFileName as String
  688.     oLogCursor = oCell.createTextCursor()
  689.     oLogCursor.CollapseToStart()
  690.     oLogCursor.HyperLinkURL = sUrl
  691.     oLogCursor.HyperLinkName = sUrl
  692.     oLogCursor.HyperLinkTarget = sUrl
  693.     LocFileName = FileNameOutOfPath(sUrl)
  694.     oCell.InsertString(oLogCursor, LocFileName,False)
  695. End Sub            
  696.  
  697.  
  698. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  699. Dim oCommentCursor as Object
  700.     If sComment <> "" Then
  701.         oCommentCursor = oCell.createTextCursor()
  702.         oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  703.         oCell.insertString(oCommentCursor, sComment, false)
  704.     End If
  705. End Sub
  706.  
  707.  
  708. Sub AddLogStatistics()
  709. Dim oCell as Object
  710. Dim oLogCursor as Object
  711. Dim MaxRowIndex as Integer
  712.     If bLogExists Then
  713.         MaxRowIndex = oLogTable.Rows.Count
  714.         sLogSummary = ReplaceString(sLogSummary, FileCount, "<COUNT>")
  715. '        oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  716. '        oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  717. '        oLogCursor = oCell.createTextCursor()
  718. '        oCell.InsertString(oLogCursor, sLogSummary,False)
  719. '        MergeRange(oLogTable, oCell, 1)
  720.  
  721.         oLogCursor = oLogDocument.Text.CreateTextCursor
  722.         oLogCursor.gotoEnd(False)
  723.         oLogCursor.HyperLinkURL = ""
  724.         oLogCursor.HyperLinkName = ""
  725.         oLogCursor.HyperLinkTarget = ""        
  726.         oLogCursor.SetString(sLogSummary)
  727.         oLogDocument.Store()
  728.         oLogDocument.Dispose()
  729.         bLogExists = False
  730.     End If
  731. End Sub
  732.  
  733.  
  734.  
  735. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  736. Dim ModuleNames() as String
  737. Dim ModuleName as String
  738. Dim MaxLibIndex as Integer
  739. Dim MaxModuleIndex as Integer
  740. Dim bMacroExists as Boolean
  741. Dim n as Integer
  742. Dim m as Integer
  743. Dim LibName as String
  744. Dim sBasicCode as String
  745. Dim oLibrary as Object
  746.     bMacroExists = False
  747.     bMacroExists = oBasicLibraries.hasElements
  748.     If bMacroExists Then
  749.         MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  750.         For n = 0 To MaxLibIndex
  751.             LibName = oBasicLibraries.ElementNames(n)
  752.             oLibrary = oBasicLibraries.getbyName(LibName)
  753.             If oLibrary.hasElements() Then
  754.                 MaxModuleIndex = Ubound(oLibrary.ElementNames())
  755.                 For m = 0 To MaxModuleIndex
  756.                     ModuleName = oLibrary.ElementNames(m)
  757.                     sBasicCode = oLibrary.getbyName(ModuleName)
  758.                     If sBasicCode <> "" Then
  759.                         ConcatComment(sComment, sReeditMacro)
  760.                         CheckIfMacroExists() = True
  761.                         Exit Function
  762.                     End If
  763.                 Next m
  764.             End If
  765.         Next n
  766.     End If
  767.     CheckIfMacroExists() = False
  768. End Function
  769.  
  770.  
  771.  
  772. Function CheckPassWordProtection(oDocument as Object)
  773. Dim bIsPassWordProtected as Boolean
  774. Dim i as Integer
  775. Dim oArgs()
  776. Dim MaxIndex as Integer
  777. Dim sblabla as String
  778.     bIsPassWordProtected = false
  779.      oArgs() = oDocument.getArgs()
  780.      MaxIndex = Ubound(oArgs())
  781.     For i = 0 To MaxIndex
  782.         sblabla = oArgs(i).Name
  783.         If oArgs(i).Name = "Password" Then
  784.             bIsPassWordProtected = True
  785.             sCurPassWord = oArgs(i).Value
  786.             Exit For
  787.         End If
  788.     Next i
  789.     CheckPassWordProtection() = bIsPassWordProtected
  790. End Function
  791.  
  792.  
  793. Sub OpenLogDocument()
  794.  
  795.     bShowLogFile = True
  796.     ImportDialogArea.endexecute()
  797.     
  798. End Sub
  799.  
  800.  
  801. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)    
  802. Dim oTableCursor as Object
  803.     oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  804.     oTableCursor.goRight(MergeCount, True)
  805.     oTableCursor.mergeRange()
  806. End Sub        
  807.  
  808.  
  809. Function ConcatComment(sComment as String, AdditionalComment as String)
  810.     If sComment = "" Then
  811.         sComment = AdditionalComment
  812.     Else
  813.         sComment = sComment & chr(13) + AdditionalComment
  814.     End If                
  815.     ConcatComment = sComment
  816. End Function
  817. </script:module>